package com.alibaba.nacos.naming.core.v2.event.client;

import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.naming.core.v2.client.Client;
import com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager;
import com.alibaba.nacos.naming.core.v2.pojo.Service;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * using by {@link ClientServiceIndexesManager}
 */
@RequiredArgsConstructor
@Getter
public class ClientOperationEvent
        extends Event {

    private final String clientId;
    private final Service service;


    public static class ClientRegisterServiceEvent
            extends ClientOperationEvent {

        public ClientRegisterServiceEvent(Service service,
                                          String clientId) {
            super(clientId, service);
        }
    }

    public static class ClientSubscribeServiceEvent
            extends ClientOperationEvent {
        public ClientSubscribeServiceEvent(Service service,
                                           String clientId) {
            super(clientId, service);
        }
    }

    public static class ClientDeregisterServiceEvent
            extends ClientOperationEvent {
        public ClientDeregisterServiceEvent(Service service,
                                            String clientId) {
            super(clientId, service);
        }
    }

    public static class ClientUnsubscribeServiceEvent
            extends ClientOperationEvent {
        public ClientUnsubscribeServiceEvent(Service service,
                                             String clientId) {
            super(clientId, service);
        }
    }

    @Getter
    public static class ClientReleaseEvent
            extends ClientOperationEvent {
        private final Client client;
        private final boolean isNative;

        public ClientReleaseEvent(Client client,
                                  boolean isNative) {
            super(client.getClientId(), null);
            this.client = client;
            this.isNative = isNative;
        }
    }

}

